<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<!DOCTYPE html >
<html>
<head>
    <script>
        function browserRedirect() {
            var sUserAgent = navigator.userAgent.toLowerCase();
            var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
            var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
            var bIsMidp = sUserAgent.match(/midp/i) == "midp";
            var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
            var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
            var bIsAndroid = sUserAgent.match(/android/i) == "android";
            var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
            var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
            if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
                window.location.href = path+"/bbqq/pifapaid.jsp";
            } else {
                return;
            }
        }
        browserRedirect();

    </script>
    <style type="text/css">
        #sp ul li {
            float: left;
            padding-left: 20px;
            padding-bottom: 10px;
            list-style: none;
            /* 	border: solid; */
        }

        .datagrid-footer {
            background-color: #f7c66c;
        }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>销售表</title>
    <link rel="stylesheet" type="text/css"
          href="easyui/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="js/datagrid-detailview.js"></script>
    <script type="text/javascript" src="js/datagrid-groupview.js"></script>
    <script type="text/javascript" src="myjs/path.js"></script>
    <script type="text/javascript" src="js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="myjs/fenxiao.js"></script>
    <script src="js/yangshi.js"></script>
</head>
<shiro:lacksPermission name="chuku:look">没有操作此模块权限。。。</shiro:lacksPermission>
<shiro:hasPermission name="chuku:look">
<body id="box" class="easyui-layout">
<div data-options="region:'north',split:true," style="width: 100%; height: 70%">
    <table id="dg" class="easyui-datagrid"
           data-options="rownumbers:false,singleSelect:true,toolbar:'#tb1',pagination:true,fit:true,striped:true,showFooter: true"
           style="width: 100%; height: 20px">
    </table>
    <div id="tb1" style="padding: 5px; height: auto">
        <div style="margin-bottom: 5px">
    <shiro:hasPermission name="chuku:create">
            <a id='xz' href="#" class="easyui-linkbutton" onclick="winOpen()"
               data-options="plain:true,iconCls:'icon-add'">新增单</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="chuku:update">
            <a id='xg' href="#" class="easyui-linkbutton" onclick="xiugai()"
               data-options="plain:true,iconCls:'icon-edit'">修改单</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="chuku:del">
            <a id='sc' href="#" class="easyui-linkbutton" onclick="del()"
               data-options="plain:true,iconCls:'icon-remove'">删除单</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="chuku:tijiao">
            <a id='tj' href="#" class="easyui-linkbutton" onclick="commit()"
               data-options="plain:true,iconCls:'icon-reload'">提交</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="chuku:bohui">
            <a id='bh' href="#" class="easyui-linkbutton" onclick="shenhe(0)"
               data-options="plain:true,iconCls:'icon-no'">驳回</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="chuku:tongguo">
            <a id='tg' href="#" class="easyui-linkbutton" onclick="shenhe(2)"
               data-options="plain:true,iconCls:'icon-ok'">通过</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="chuku:chuku">
            <a href="#" class="easyui-linkbutton" onclick="chuku()" data-options="plain:true,iconCls:'icon-redo'"
               id='rukuspan'>出库</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="chuku:print">
            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-print'"
               onclick='print()' id="print">打印订单</a>
    </shiro:hasPermission>

            <%--<shiro:hasPermission name="chuku:chexiao"><a id='cx' href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-clear'"
               onclick="undoCK()">撤销订单</a></shiro:hasPermission>
   --%>
           <%-- <shiro:hasPermission name="chuku:pic">
            <a id='pic' href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-clear'"
               onclick="huiPic()">回执图片</a></shiro:hasPermission>--%>


        </div>

        <div>
            制单日期从:<input class="easyui-datebox" id="qtime" style="width: 120px">
            到:<input class="easyui-datebox" id="etime" style="width: 120px"> <input id="bumeng" class="easyui-combotree" data-options=""  style="width: 160px;">

            <input id="key" class="easyui-searchbox" data-options="prompt:'输入客户名/单号搜索',searcher:getChuKuList" style="width: 200px"></input>
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="chongzhi()">重置搜索</a>
            <label id='zt11'><input type="checkbox" value="1" id="zt1" checked="checked"><span>查看草稿</span></label>
            <label id='zt22'><input type="checkbox" value="2" id="zt2" checked="checked"><span>查看已提交</span></label>
            <label id='zt33'><input type="checkbox" value="3" id="zt3" ><span>查看已审核</span></label>
            <label id='zt44'><input type="checkbox" value="4" id="zt4" ><span>查看已出库单</span></label>

        </div>

    </div>

</div>

<div data-options="region:'center',border:false" style="height: 40%; width: 100%">
    <div id="tb3" style="padding: 5px; height: auto">
        <span>详细信息 | </span>
        <label><input type='radio' onclick='loadChildren(0)' checked='checked' class='fenlei' name="fenlei" value='0'>按款号</label>
        <label><input type='radio' onclick='loadChildren(1)' class='fenlei' name="fenlei" value='1'><span>按颜色</span></label>
        <label><input type='radio' onclick='loadChildren(2)' name="fenlei" class='fenlei'  value='2'><span>按尺码</span></label>
    </div>
    <table id="subDatagrid">

    </table>
</div>

<!-- 新增===================================================================================================== -->
<div id="w" class="easyui-window" title="销售单"
     data-options="buttons:'#bs', modal:true,closed:true,collapsible:false,iconCls:'icon-save',minimizable:false,maximizable:true,closable:false"
     style="width: 70%; min-height: 600px; min-width: 1001px">
    <table style="width: 100%; margin-bottom: 15px; padding-bottom: 5px;margin: 0 auto">
        <tr>
            <th colspan="6" style="text-align: center"><h2 id='h2'>销 售 单</h2> <input id='xiugaizhuantai' type='hidden'>
            </th>
        </tr>

        <tr>
            <td>客户名称:</td>
              <td>  <input id="chukuId" type="text" hidden="hidden">
                  <input id="fenxiaoshang" class="easyui-combobox" data-options=""  style="width: 160px;">
            </td>
            <td>收货地址:</td>
            <td>
                <input class="easyui-validatebox textbox" style="height: 22px"
                       data-options="validType:'length[0,20]',novalidate:true" id="SHDZ">
            </td>
            <td class='pfdh'>订单总额/￥：<span style="font-size: larger" id="zongjia">0.00</span></td>

        </tr>

        <tr>
            <td>联系方式:</td>
            <td>
                <input class="easyui-validatebox textbox" style="height: 22px"
                       data-options="required:true,validType:'length[0,11]',novalidate:true" id="phone">
            </td>
            <td>所属年季<span style="color: red">*</span>：</td>
            <td>
                <input class="easyui-combobox" data-options="required:true,valueField:'id',textField:'text',editable:false"   style="height: 22px;" id="yearandseason">
            </td>

            <td>
                <span style=" text-align:right;">款数/款：</span><span id="zongkuanshu" style="font-size: larger">0</span>
                <br/><span style="text-align:right">件数/件：</span><span id="zongjianshu" style="font-size: larger">0</span>

            </td>
        </tr>
    </table>

    <!--编辑 表格栏-->
    <table id="bjdg" class="easyui-datagrid" title="订单编辑"
           data-options="rownumbers:false,singleSelect:true,toolbar:'#tb21',striped:true,showFooter: true"
           style="width: 100%;height:70%">
    </table>

    <div id="tb21" style="height: auto">
        <span title="按Enter进行快捷填充数据" class="easyui-tooltip" data-options="position: 'top'">
            商品款号：<input id="se" class="easyui-combobox" style="width: 140px;"></input></span>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="refresh()">刷新</a>
        <span title="按Enter进行快捷填充数据" class="easyui-tooltip" data-options="position: 'top'">
            <select id="cc" style="width: 140px;" class="easyui-combobox"></select><div id="sp"></div><!--下拉器--></span>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true"
           onclick="accept()">保存编辑</a></span>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true"
           onclick="removeit()">删除新增</a>
        <input class="easyui-searchbox" data-options="prompt:'输入款号进行搜索',searcher:doSearch" style="width: 130px"></input>
        <span title="整单改折扣" class="easyui-tooltip"><label><input id='zk1' type='radio' checked='checked' name='zk1'>折扣一</label></span>
        <span title="单款改折扣" class="easyui-tooltip"> <label><input id='zk2' type='radio' name='zk1'>折扣二</label></span>
        <div id="clear" style="float: clear;"></div>
    </div>
    <div id="bs"  class="dialog-button">
				<span title="按住Ctrl+Enter进行快捷保存" class="easyui-tooltip" data-options="position: 'top'">
				<button id="save1" onclick="addChuKu()" class="easyui-linkbutton"
                        data-options="iconCls:'icon-save'">生成单</button></span>
        <button id="noqiuxiao" onclick="winClose()" class="easyui-linkbutton" data-options="iconCls:'icon-no'">取消
        </button>
    </div>

</div>
<script>

    //搜索
    function doSearch(value) {

        var ii = $('#bjdg').datagrid('getRows').length;
        var j = 0;
        for (var i = 0; i < ii; i++){
            if ($('#bjdg').datagrid('getData').rows[i].product.indexOf(value)!=-1) {
                $('#bjdg')
                    .datagrid(
                        'insertRow',
                        {
                            index : j,
                            row : {
                                id: $('#bjdg').datagrid('getData').rows[i].id,
                                product: $('#bjdg').datagrid('getData').rows[i].product,
                                productName: $('#bjdg').datagrid('getData').rows[i].productName,
                                color: $('#bjdg').datagrid('getData').rows[i].color,
                                size: $('#bjdg').datagrid('getData').rows[i].size,
                                pinpai: $('#bjdg').datagrid('getData').rows[i].pinpai,
                                year: $('#bjdg').datagrid('getData').rows[i].year,
                                season: $('#bjdg').datagrid('getData').rows[i].season,
                                price: $('#bjdg').datagrid('getData').rows[i].price,
                                zhekou: $('#bjdg').datagrid('getData').rows[i].zhekou,
                                sjdanjia: $('#bjdg').datagrid('getData').rows[i].sjdanjia,
                                shuliang: $('#bjdg').datagrid('getData').rows[i].shuliang,
                                sjzongjia: $('#bjdg').datagrid('getData').rows[i].sjzongjia
                            },rowStyler:function(index,row){
                               /* if(index>0)*/
                            return 'background-color:pink;color:blue;font-weight:bold;';
                        }
                        });

                $('#bjdg').datagrid('deleteRow', i + 1);
                j++
            }
        }
    }
    //编辑栏生成
    $(function () {
        $('#cc').combo({
            editable: false,
            panelWidth: 500,
            panelHeight: 240
        });
        $('#sp').appendTo($('#cc').combo('panel'));
    });

    $(document).keyup(function (event) {
        if (event.shiftKey && event.keyCode == 13) {
            accept()
        }
          if (event.ctrlKey && event.keyCode == 13) {
            $('#save').trigger('click')
        }
    })

var flag=false;//解决款号栏，回车t
    function diaoyong(tar) {
        if (event.shiftKey) {
            $(tar).parents('tr').next().find('input').eq(0).blur();
            return
        }
        if (event.keyCode == 13) {
            if (flag) {
                //取到当前填写的数

                //数量
                if($(tar).val()!=''){
                    var shuliang = $(tar).val() - 0;
                    var count = $(tar).parents('td').siblings('td').find('input').length
                    for (var i = 0; i < count - 1; i++) {
                        $(tar).parents('td').siblings('td').find('input').eq(i).val(shuliang)
                    }
                    $(tar).parents('td').siblings('td').find('input').eq(count - 1).val(shuliang * count)
                }

                $(tar).parents('tr').next().find('input').eq(0).focus();
            }
            flag = true
        }

    }

    //小计
    function diaoyong1(tar) {
        if (event.shiftKey) {
            $(tar).parents('tr').next().find('input').eq(0).blur();
            return
        }
        if (event.keyCode == 13) {
            if($(tar).val()!=''){
                var count = $(tar).parents('td').siblings('td').find('input').length
                var zongji = $(tar).val() - 0;
                //得到这个数量
                var sl = zongji / count
                for (var i = 0; i < count; i++) {
                    $(tar).parents('td').siblings('td').find('input').eq(i).val(sl);
                }
            }

            $(tar).parents('tr').next().find('input').eq(count).focus();
        }
    }


</script>




<div id="wpicture" class="easyui-window" title="添加回执单"
     data-options="modal:true,closed:true,iconCls:'icon-save',maximizable:false,minimizable:false,closable:true,collapsible:false"
     style="width: 380px; height: 200px; padding: 10px;">
    <h2>添加回执单</h2>
    <div style="display:none" align="center" id="imgDiv">
        <img alt="" src="" id="img" name="图片预览" width="200" height="200" id="图片预览">
    </div>
    <form  name="form1" method="post" action=""
           enctype="multipart/form-data">
        <input name="upfile" type="file" id="txtSrc" onChange="setImagePreview(this,imgDiv,img);">
        <input  type="button" value="上传"  onclick="doUpload()">
    </form>

    <script>

        //添加回执单图片
        function huiPic(){
            $('#wpicture').window('open')
        }
        //添加回执单图片
        function huiPicClose(){
            $('#img').attr("src","")
            $('#txtSrc').val("")
            $('#wpicture').window('close')
        }

        function doUpload() {

            if ($('#bumeng').combotree('getValue') != $("#jgid").val()) {
                alert("不可以操作非本机构数据！");
                return;
            }
            if($('#txtSrc').val()==''){
                alert("无图片!")
                return
            }
            if($('#dg').datagrid("getSelected").state!=3){

                alert("不是出库状态,不可添加回执单!")
            }
            $.ajaxFileUpload({
                    url : path+"/pic/upfile.do",
                    secureuri : false,
                    fileElementId : "txtSrc",
                    dataType : 'json',
                     data:{
                        chukuId:$('#dg').datagrid("getSelected").id
                     },
                    success : function(data) {
                        if(data.code==200){
                                huiPicClose()
                                $.messager.show({
                                    title:'提示',
                                    msg:data.msg,
                                    timeout:400,
                                    showType:'slide'
                                });
                                getChuKuList()
                            }else {
                            alert(data.msg)
                        }
                    },
                    error : function(XMLHttpRequest, textStatus,
                                     errorThrown) {
                       /* alert('上传失败！');*/
                    }
                });

        }


        function setImagePreview(docObj,localImagId,imgObjPreview) {
            var name=docObj.value;
            var type=name.split(".");
            type=type[type.length-1];
            if("jpg"!=type &&"png"!=type &&"jpeg"!=type&&"gif"!=type){
                alert("错误的类型，请选择图片");
                document.getElementById("txtSrc").value=null;//防止将非图片类型上传
                return ;
            }
                   if(docObj.files[0].size/1024>2048){
                       $('#txtSrc').val("")
                     alert("上传图片不能大于2M")
                       return
                   }
            if(docObj.files && docObj.files[0])
            {

                //alert("hello"+docObj.files[0]);
                //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
                document.getElementById("imgDiv").style.display="block";
                document.getElementById("img").src= window.URL.createObjectURL(docObj.files[0]);
            }
            else
            {
                //IE下，使用滤镜
                docObj.select();
                var imgSrc = document.selection.createRange().text;

                //必须设置初始大小
                localImagId.style.width = "300px";
                localImagId.style.height = "200px";

                //图片异常的捕捉，防止用户修改后缀来伪造图片
                try
                {
                    localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
                    localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
                }
                catch(e)
                {
                    alert("您上传的图片格式不正确，请重新选择!");
                    return false;
                }
                imgObjPreview.style.display = 'none';
                document.selection.empty();
            }
            return true;
        }

    </script>

</div>


<script>
    function as(url){
               $('#picc').window('open')
               $('#picimg').attr("src","http://"+window.location.host+path+url);
    }
    function huiPic1(){
        $('#picc').window('close')
        huiPic()
    }

</script>
<div id="picc" class="easyui-window" title="查看" data-options="closable:true,modal:true,closed:true,iconCls:'icon-save'" style="width:500px;height:200px;padding:10px;" >
      <img src="" id="picimg">
      <input type="button" value="重传" onclick="huiPic1()">

</div>
<input id='jgid' type="hidden"  value="<%=request.getParameter("jgid")%>">
<input id='parentId' type="hidden"  value="<%=request.getParameter("parentId")%>">
<input id='jgleixing' type="hidden"  value="<%=request.getParameter("jgleixing")%>">

</body>
</shiro:hasPermission>
</html>

